<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
    <title>美策平台</title>
    <link rel="icon" type="image/png" href="/img/icon.png">
    <link rel="stylesheet" type="text/css" href="../../datepicker/jquery-ui.min.css">
    <link rel="stylesheet" type="text/css" href="../../css/app.css">
    <link rel="stylesheet" type="text/css" href="../../css/index.css">
    <script type="text/javascript" src="../../js/jquery.min.js"></script>
    <script type="text/javascript" src="/pc/js/all.js"></script>
    <style>
        #addJob2Tlb { padding:10px 20%;
    background:#0088cc;border-radius:5px;
    border:0;color:#ffffff; }
    </style>
</head>
<body>
<!--
    制作者：九哥
    页面：发布岗位2页面
    时间：2019-03-01
-->


<style type="text/css">
    .detail::before{
        content: '*';
        display: inline-block;
        color: #de373e;
    }
    .submit button{
        width: 80%;
        padding: 10px 20%;
        background: #0088cc;
        border-radius: 5px;
        border: 0;
        color: #ffffff;
    }
</style>


<!----------发布岗位页面---------->
<div id="addJob2Page"><!--此ID页面切换用-->
    <div id="addJob2Title">
        <b>发布岗位</b>
        <img src="../../images/return.png" id="addJob2Rtn">
    </div>
    <div id="addJob2Detail">
        <p class="title">职位：<b id="job_name"></b></p>
        <div class="detail">人数
            <span><input name="num" type="text" placeholder="请输入"></span>
            <br>
        </div>
        <div class="detail">月薪
            <span><input name="emolument" type="text" placeholder="请输入"></span>
            <br>
        </div>
        <div class="detail">技术工种
            <span><input type="text" name="skill" type="text" placeholder="请输入"></span>
        </div>
        <div class="detail">休班制度
            <ul>
                <li><input name="rest" type="radio" value="1">单休</li>
                <li><input name="rest" type="radio" value="2">双休</li>
            </ul>
            <br>
        </div>
        <div class="detail">福利待遇
                <ul>
                    <li><input name="welfare" type="radio" value=1>包住</li>
                    <li><input name="welfare" type="radio" value=2>包吃</li>
                    <li><input name="welfare" type="radio" value=3>暂无</li>
                </ul>
                <br>
            </div>
        <div class="detail">学历
            <ul>
                <li><input name="education" type="radio" value=1>小学</li>
                <li><input name="education" type="radio" value=2>初中</li>
                <li><input name="education" type="radio" value=3>高中</li>
                <li><input name="education" type="radio" value=4>大专</li>
                <li><input name="education" type="radio" value=5>本科</li>
                <li><input name="education" type="radio" value=7>其他</li>
            </ul>
            <br><br>
        </div>
        <div class="detail">工作年限
            <ul>
                <li><input name ="work_year" type="radio" value=1>1年以内</li>
                <li><input name ="work_year" type="radio" value=2>1-2年</li>
                <li><input name ="work_year" type="radio" value=3>3-5年</li>
                <li><input name ="work_year" type="radio" value=4>5年以上</li>
            </ul>
            <br><br><br>
        </div>
        <div class="detail">性别要求
            <ul>
                <li><input name="sex" type="radio" value=0>不限</li>
                <li><input name="sex" type="radio" value=1>男</li>
                <li><input name="sex" type="radio" value=2>女</li>            
            </ul>
        </div>
        <div class="detail">年龄要求
            <input type="text" name="age_range1" placeholder="请输入" style="width:50px"> ~ <input type="text" placeholder="请输入" name="age_range2" style="width:50px">
        </div>
        <div class="detail">工作地点
            <span><input name="address" placeholder="请输入" type="text"></span>
        </div>
        <div class="detail">职位描述
            <span><input name="detail" placeholder="请输入" type="text"></span>
        </div>
        <div class="detail">工作内容
            <span><input name="content" placeholder="请输入" type="text"></span>
        </div>
        <div class="detail">工作时间
            <span><input name="work_hour" placeholder="请输入" type="text"></span>
        </div>
        <div class="detail">联系人
            <span><input name="contact_name" placeholder="请输入" type="text"></span>
        </div>
        <div class="detail">联系电话
            <span><input name="contact_telephone" placeholder="请输入" type="text"></span>
        </div>
        <div class="detail">邮箱
            <span><input name="email" placeholder="请输入" type="text"></span>
        </div>
        <div class="detail">推广：暂时免费</div>
        <!-- <p class="submit">
            <button type="button" id="addJob2" onclick="test();return false;">发布</button>
        </p> -->
        <p class="submit">
            <button type="button" id="addJob2Tlb" data-status="0">发布</button>
        </p>
    </div>
</div>
<!----------发布岗位页面---------->





<!----------错误提示---------->
<div id="errMsg"></div>
<!----------错误提示---------->
</body>
<script type="text/javascript" src="../../js/indexPageChange.js"></script>
<script type="text/javascript" src="../../js/index.js"></script>
<script type="text/javascript" src="../../js/alertMsg.js"></script>
<script type="text/javascript">
    document.getElementById('job_name').innerHTML = localStorage.getItem('addjob_job_name');
    $("#addJob2Rtn").click(function(){
        window.location.href = "../addJob.html";
    })
    $("#addJob2Tlb").click(function(){
        if ($(this).attr('data-status') != 0) { // 去除多次点击
            return false
        }
        $(this).attr('data-status', 1)
        var token = JSON.parse(localStorage.getItem('userInfo')).token;
        var jobId = localStorage.getItem('addjob_job_id');                  // 职位id
        var num = $("input[name='num']").val();                             // 招聘人数
        var emolument = $('input[name = emolument]').val();                 // 薪酬
        var skill = $('input[name = skill]').val();                         // 技术工种
        var rest = $('input[name = rest]:checked').val();                     // 休息制度
        var welfare = $("input[name='welfare']:checked").val();               // 福利待遇
        var education = $('input[name = education]:checked').val();           // 学历
        var work_year = $('input[name = work_year]:checked').val();           // 工作年限
        var sex = $('input[name = sex]:checked').val();                       // 性别
        var age_range1 = $("input[name='age_range1']").val();               // 年龄要求开始
        var age_range2 = $("input[name='age_range2']").val();               // 年龄要求结束
        var address = $("input[name='address']").val();                     // 工作地点
        var detail = $("input[name='detail']").val();                       // 职位描述
        var content = $("input[name='content']").val();                     // 工作内容
        var work_hour = $("input[name='work_hour']").val();                 // 工作时间
        var contact_name = $("input[name='contact_name']").val();           // 联系人
        var contact_telephone = $("input[name='contact_telephone']").val(); // 联系电话
        var email = $("input[name='email']").val();                         // 邮箱
        var name = {
            token: {name: 'token', value: token },
            job: {name: '职位id', value: jobId },
            num: {name: '招聘人数', value: num },
            emolument: {name: '薪酬', value: emolument },
            skill: {name: '技术工种', value: skill},
            rest: {name: '休息制度', value: rest },
            welfare: {name: '福利待遇', value: welfare },
            education: {name: '学历', value: education },
            work_year: {name: '工作年限', value: work_year },
            sex: {name: '性别', value: sex },
            age_range: {name: '年龄要求', value: age_range1 + ',' + age_range2, value1: age_range1, value2: age_range2 },
            address: {name: '工作地点', value: address },
            detail: {name: '职位描述', value: detail },
            content: {name: '工作内容', value: content },
            work_hour: {name: '工作时间', value: work_hour },
            contact_name: {name: '联系人', value: contact_name },
            contact_telephone: {name: '联系电话', value: contact_telephone },
            email: {name: '邮箱', value: email },
        }
        var data = {};
        try {
            Object.keys(name).forEach(function(k){
            if (k === 'age_range') {
                if (name[k]['value1'] === '' || name[k]['value2'] === '') {
                    throw new Error(name[k]['name'] + '不能为空')
                }   
            }
            if (k === 'email') {
                var reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
                if (!reg.test(email)) {
                    throw new Error(name[k]['name'] + '格式错误')
                }
            }
            if (!name[k]['value'] || name[k]['value'] === '' || name[k]['value'] === undefined) {
                throw new Error(name[k]['name'] + '不能为空')
            }

            data[k] = name[k]['value']
        });
        } catch (e) {
            alertMsg(e.message)
            return
        }
        
        $.ajax({
        url: '/api/home/release/recruit',
        type:'post',
        data:JSON.stringify(data),
        dataType:'json',
        contentType: "application/json",
        // async: false,
        success: function (result) {
            if (result.code === 200) {
                alertMsg('发布成功');
                setTimeout(function() {
                    window.location.href = '../../index.html';
                }, 1000)
            }else{
                alertMsg(result.msg); 
            }
        }
    }); 
    })

</script>
</html>